﻿using System;
using System.Collections.Generic;
using Omu.AwesomeDemo.Core.Model;

namespace Omu.AwesomeDemo.Data
{
    public static class Db
    {
        static Db()
        {
            var r = new Random();

            foreach (var o in Persons)
            {
                o.Country = Countries[r.Next(22)];
                o.Home = Countries[r.Next(22)];
                var ho = new List<Hobby>();
                for (var i = 0; i < r.Next(2, 7); i++)
                {
                    var h1 = h[r.Next(32)];
                    if (!ho.Contains(h1)) ho.Add(h1);
                }


                o.Hobbies = ho;
                o.DateOfBirth = new DateTime(r.Next(1980, 2000), r.Next(1, 12), r.Next(1, 28));
            }
        }

        public static int Sequence = 100;
        public static IList<T> Table<T>() where T : Entity
        {
            if (typeof(T) == typeof(Person)) return Persons as IList<T>;
            if (typeof(T) == typeof(Country)) return Countries as IList<T>;
            if (typeof(T) == typeof(Hobby)) return h as IList<T>;
            if (typeof(T) == typeof(Foobar)) return Foobars as IList<T>;
            if (typeof(T) == typeof(Show)) return Shows as IList<T>;
            if (typeof(T) == typeof(Role)) return roles as IList<T>;
            if (typeof(T) == typeof(User)) return users as IList<T>;
            if (typeof(T) == typeof(Fruit)) return Fruits as IList<T>;
            return null;
        }

        private static readonly IList<Fruit> Fruits = new List<Fruit>
        {
            new Fruit{Id = 1, Name = "Banana"},
            new Fruit{Id = 2, Name = "Mango"},
            new Fruit{Id = 3, Name = "Apple"},
            new Fruit{Id = 4, Name = "Strawberry"},
            new Fruit{Id = 5, Name = "Papaya"},
            new Fruit{Id = 6, Name = "Coconut"},
            new Fruit{Id = 7, Name = "Cherry"},
            new Fruit{Id = 8, Name = "Avocado"},
            new Fruit{Id = 9, Name = "Kiwi"},
        };

        private static readonly IList<Role> roles = new List<Role>
                                                        {
        new Role{Id = 1, Name = "admin"},
        new Role{Id = 2, Name = "superuser"},
        new Role{Id = 3, Name = "sysadmin"},
        new Role{Id = 4, Name = "owner"},
        new Role{Id = 5, Name = "user"},
        new Role{Id = 6, Name = "turist"},
        new Role{Id = 7, Name = "reader"},
    };

        private static readonly IList<User> users = new List<User>
                                                        {
        new User{Id = 1, Name = "admin", Roles = new[]{roles[0],roles[1],roles[2]}},
        new User{Id = 2, Name = "super", Roles = new[]{roles[1],roles[2]}},
        new User{Id = 3, Name = "me", Roles = new[]{roles[2],roles[3]}},
        new User{Id = 4, Name = "user", Roles = new[]{roles[4]}},
        new User{Id = 5, Name = "someone", Roles = new[]{roles[5]}},
    };

        private static readonly IList<Country> Countries = new List<Country>
                                                                     {
                                                                         new Country { Id = 1, Name = "USA" },
                                                                         new Country { Id = 2, Name = "UK" },
                                                                         new Country { Id = 3, Name = "Moldova" },
                                                                         new Country { Id = 4, Name = "France" },
                                                                         new Country { Id = 5, Name = "Italy" },
                                                                         new Country { Id = 6, Name = "Germany" },
                                                                         new Country { Id = 7, Name = "Belgium" },
                                                                         new Country { Id = 8, Name = "Japan" },
                                                                         new Country { Id = 9, Name = "China" },
                                                                         new Country { Id = 10, Name = "Russia" },
                                                                         new Country { Id = 11, Name = "Mexico" },
                                                                         new Country { Id = 12, Name = "Canada" },
                                                                         new Country { Id = 13, Name = "Panama" },
                                                                         new Country { Id = 14, Name = "Argentina" },
                                                                         new Country { Id = 15, Name = "Brazil" },
                                                                         new Country { Id = 16, Name = "Columbia" },
                                                                         new Country { Id = 17, Name = "Austria" },
                                                                         new Country { Id = 18, Name = "Greece" },
                                                                         new Country { Id = 19, Name = "Spain" },
                                                                         new Country { Id = 20, Name = "India" },
                                                                         new Country { Id = 21, Name = "Alpachirlandia" },
                                                                         new Country { Id = 22, Name = "Botswana" },
                                                                         new Country { Id = 23, Name = "Australia" },
                                                                     };

        private static readonly IList<Hobby> h = new List<Hobby>
                                                                     {
                                                                         new Hobby { Id = 1, Name = "swimming"},
                                                                         new Hobby { Id = 2, Name = "gaming"},
                                                                         new Hobby { Id = 3, Name = "stackoverflow" },
                                                                         new Hobby { Id = 4, Name = "open-source" },
                                                                         new Hobby { Id = 5, Name = "martial arts" },
                                                                         new Hobby { Id = 6, Name = "parkour" },
                                                                         new Hobby { Id = 7, Name = "sleeping" },
                                                                         new Hobby { Id = 8, Name = "shopping" },
                                                                         new Hobby { Id = 9, Name = "drinking" },
                                                                         new Hobby { Id = 10, Name = "eating" },
                                                                         new Hobby { Id = 11, Name = "pwning nubz" },
                                                                         new Hobby { Id = 12, Name = "YoYo" },
                                                                         new Hobby { Id = 13, Name = "yoga" },
                                                                         new Hobby { Id = 14, Name = "walking" },
                                                                         new Hobby { Id = 15, Name = "tennis" },
                                                                         new Hobby { Id = 16, Name = "tetris" },
                                                                         new Hobby { Id = 17, Name = "football" },
                                                                         new Hobby { Id = 18, Name = "fishing" },
                                                                         new Hobby { Id = 19, Name = "darts" },
                                                                         new Hobby { Id = 20, Name = "ghost hunting" },
                                                                         new Hobby { Id = 21, Name = "hiking" },
                                                                         new Hobby { Id = 22, Name = "legos" },
                                                                         new Hobby { Id = 23, Name = "eating out" },
                                                                         new Hobby { Id = 24, Name = "bowling" },
                                                                         new Hobby { Id = 25, Name = "beatboxing" },
                                                                         new Hobby { Id = 26, Name = "meditation" },
                                                                         new Hobby { Id = 27, Name = "walking" },
                                                                         new Hobby { Id = 28, Name = "origami" },
                                                                         new Hobby { Id = 29, Name = "running" },
                                                                         new Hobby { Id = 30, Name = "robotics" },
                                                                         new Hobby { Id = 31, Name = "surfing" },
                                                                         new Hobby { Id = 32, Name = "wine making" },
                                                                         new Hobby { Id = 33, Name = "cooking" },
                                                                     };
        private static readonly IList<Show> Shows = new List<Show>
        {
            new Show{Id = 1, Name = "Athene"},
            new Show{Id = 2, Name = "South Park"},
            new Show{Id = 3, Name = "Married... With Children"},
            new Show{Id = 4, Name = "Ocean's 11"},
            new Show{Id = 5, Name = "Friends"},
            new Show{Id = 6, Name = "Kenan & Kel"},
            new Show{Id = 7, Name = "Two and a half men"},
        };

        private static readonly IList<Person> Persons = new List<Person>
        {
            new Person {Id = 1, Show = Shows[3], FirstName = "Danny", LastName = "Ocean",    Login = "danny", },
            new Person {Id = 2, Show = Shows[1], FirstName = "Eric", LastName = "Cartman",    Login = "cartmenez", },
            new Person {Id = 3, Show = Shows[1], FirstName = "Randy", LastName = "Marsh",    Login = "randy", },
            new Person {Id = 4, Show = Shows[1], FirstName = "Leopold", LastName = "Butters Stotch",    Login = "profesor chaos", },
            new Person {Id = 5, Show = Shows[1], FirstName = "Coon", LastName = "and Friends",    Login = "coon", },
            new Person {Id = 6, Show = Shows[1], FirstName = "Kenny", LastName = "McCormick",    Login = "mysterion", },
            new Person {Id = 7, Show = Shows[1], FirstName = "Kyle", LastName = "Broflovski",    Login = "kyle", },
            new Person {Id = 8, Show = Shows[3], FirstName = "Linus", LastName = "Caldwell",    Login = "man3", },
            new Person {Id = 9, Show = Shows[3], FirstName = "Livingston", LastName = "Dell",    Login = "man2", },
            new Person {Id = 10, FirstName = "Jhon", LastName = "Smith",    Login = "man1", },
            new Person {Id = 11, Show = Shows[0], FirstName = "Ian", LastName = "De Bruyn",    Login = "cameraman", },
            new Person {Id = 12, FirstName = "Jack", LastName = "Sparrow",    Login = "sparrow", },
            new Person {Id = 13, FirstName = "James", LastName = "Bond",    Login = "bond", },
            new Person {Id = 14, Show = Shows[5], FirstName = "Kel", LastName = "Kimble ",    Login = "kel", },
            new Person {Id = 15, Show = Shows[5], FirstName = "Kenan", LastName = "Rockmore",    Login = "kenan", },
            new Person {Id = 16, Show = Shows[5], FirstName = "Pete", LastName = "Wrigley",    Login = "pete", },
            new Person {Id = 17, Show = Shows[6], FirstName = "Charlie", LastName = "Harper",    Login = "charlie", },
            new Person {Id = 18, Show = Shows[6], FirstName = "Alan", LastName = "Harper",    Login = "alan", },
            new Person {Id = 19, Show = Shows[6], FirstName = "Jake", LastName = "Harper",    Login = "kateers", },
            new Person {Id = 20, Show = Shows[6], FirstName = "Evelyn", LastName = "Harper",    Login = "evil", },
            new Person {Id = 21, Show = Shows[2],  FirstName = "Al", LastName = "Bundy",    Login = "salesman", },
            new Person {Id = 22, Show = Shows[2],  FirstName = "Peggy", LastName = "Bundy",    Login = "peg", },
            new Person {Id = 23, Show = Shows[2],  FirstName = "Bud", LastName = "Bundy",    Login = "beer", },
            new Person {Id = 24, Show = Shows[2],  FirstName = "Kelly", LastName = "Bundy",    Login = "pumpkin", },
            new Person {Id = 25, Show = Shows[4], FirstName = "Chandler", LastName = "Bing",    Login = "chandler", },
            new Person {Id = 26, Show = Shows[4], FirstName = "Rachel", LastName = "Green",    Login = "rachel", },
            new Person {Id = 27, Show = Shows[4], FirstName = "Dr. Ross", LastName = "Geller",    Login = "dino", },
            new Person {Id = 28, Show = Shows[4], FirstName = "Monica", LastName = "Geller",    Login = "monica", },
            new Person {Id = 29, Show = Shows[4], FirstName = "Joey", LastName = "Tribiani",    Login = "joey", },
            new Person {Id = 30, Show = Shows[4], FirstName = "Phoebe", LastName = "Buffay",    Login = "phoebes", },
            new Person {Id = 31, Show = Shows[0], FirstName = "Fien", LastName = "Leysen",    Login = "twinklybird", },
            new Person {Id = 32, Show = Shows[0], FirstName = "Chiren", LastName = "Boumaaza",    Login = "Athene", },
            new Person {Id = 33, Show = Shows[0], FirstName = "Tania", LastName = "Derveaux",    Login = "Tanialicious", },
            new Person {Id = 34, Show = Shows[0], FirstName = "Dries", LastName = "Leysen",    Login = "Abraham", },
            new Person {Id = 35, Show = Shows[0], FirstName = "Daan", LastName = "Leysen",    Login = "Furious", },
            new Person {Id = 36, FirstName = "Deuce", LastName = "Bigalow",    Login = "deuce", },
        };

        private static readonly IList<Foobar> Foobars = new List<Foobar>
        {
            new Foobar{Id = 1, Person = Persons[1], Show = Shows[4], Character = Persons[29], Name = "foobar",  Person2 = Persons[3], Hobby = h[20]},
            new Foobar{Id = 2, Person = Persons[4], Show = Shows[3],  Character = Persons[0], Name = "barz",  Person2 = Persons[1], Hobby = h[21]},
            new Foobar{Id = 3, Person = Persons[18], Show = Shows[1],  Character = Persons[5], Name = "foo",  Person2 = Persons[2],Hobby = h[22]},
            new Foobar{Id = 4, Person = Persons[13], Show = Shows[5],  Character = Persons[14], Name = "knatz",  Person2 = Persons[4],Hobby = h[23]},
            new Foobar{Id = 5, Person = Persons[26], Show = Shows[2],  Character = Persons[23], Name = "kazranub",  Person2 = Persons[5],Hobby = h[24]},
            new Foobar{Id = 6, Person = Persons[10], Show = Shows[6],  Character = Persons[16], Name = "darius",  Person2 = Persons[27],Hobby = h[25]},
            new Foobar{Id = 7, Person = Persons[31], Show = Shows[0],  Character = Persons[32], Name = "1337 king",  Person2 = Persons[12],Hobby = h[21]},
            new Foobar{Id = 8, Person = Persons[34], Show = Shows[1],  Character = Persons[4], Name = "furious",  Person2 = Persons[21],Hobby = h[31]},
            new Foobar{Id = 9, Person = Persons[2], Show = Shows[2],  Character = Persons[22], Name = "zeratul",  Person2 = Persons[29],Hobby = h[32]},
        };
    }
}
